package edu.cs.usask.ca.silver.plugin.rcp.dialogs.create;

import java.util.Hashtable;

import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.ui.PlatformUI;

import edu.cs.usask.ca.silver.businesslogic.ids.ScenarioID;
import edu.cs.usask.ca.silver.plugin.rcp.components.SilverNameEnums;

/**
 * A class the provides the RCP UI add new scenario dialog box with relevant
 * data. It list the columns and data the are needed in order to create a new
 * scenario. This columns that need to be edited are grayed out to indicate that
 * the data is editable. The editing support is called to read the changes made
 * to a cell and that data is updated to the appropriate hashtable.
 * 
 * similar to "AddScenarioTableColumnLabelProvider.java"
 * 
 * @author Alan Yeung, Mike Taylor
 * 
 */

public class CreateScenarioTableColumnLabelProvider {

	public CreateScenarioDialog newScenarioDialog;
	public ScenarioID scenarioId;

	public CreateScenarioTableColumnLabelProvider(
			CreateScenarioDialog newScenarioDialog, ScenarioID scenarioId) {
		this.newScenarioDialog = newScenarioDialog;
		this.scenarioId = scenarioId;

	}

	/**
	 * A method that actually fleshes out the data to be displayed in the table
	 * viewer for the parameter that are associated with a baseline scenario and
	 * are editable.
	 * 
	 * @param viewer
	 *            the table viewer that these column belong
	 */
	public void createColumns(TableViewer viewer) {

		// Column 0: Name
		TableViewerColumn nameColumn = new TableViewerColumn(viewer, SWT.NONE);
		nameColumn.getColumn().setWidth(150);
		nameColumn.getColumn().setText("Name");
		nameColumn.getColumn().setMoveable(true);
		nameColumn.setLabelProvider(new ColumnLabelProvider() {

			@Override
			@SuppressWarnings("unchecked")
			public String getText(Object element) {
				// logger.info("element : "+ ((Hashtable<String, String>)
				// element).get("Name"));
				// return ((Hashtable<String, String>) element).get("Name");
				return ((Hashtable<String, String>) element)
						.get(SilverNameEnums.NAME.name());
			}
		});

		// Column 2: Value
		TableViewerColumn valueColumn = new TableViewerColumn(viewer, SWT.NONE);
		valueColumn.getColumn().setWidth(100);
		valueColumn.getColumn().setText("Value");
		valueColumn.getColumn().setMoveable(true);
		valueColumn.setLabelProvider(new ColumnLabelProvider() {

			@Override
			@SuppressWarnings("unchecked")
			public String getText(Object element) {
				return ((Hashtable<String, String>) element)
						.get(SilverNameEnums.VALUE.name());
				// return
				// ProjectsViewer.adapterFactory.getParameterValue(scenarioId,
				// (ParameterID) element);
			}

			// public Color getBackground(Object element){
			// return new Color(PlatformUI.createDisplay() ,50,50,0);
			// }
			@Override
			public Color getForeground(Object element) {
				return new Color(PlatformUI.createDisplay(), 155, 155, 155);
			}
		});

		/*
		 * call to editing support to update the array of hashtable to represent
		 * the user desired changes
		 */
		valueColumn.setEditingSupport(new CreateScenarioEditingSupport(viewer,
				SilverNameEnums.VALUE.name(), newScenarioDialog));

		// Column 4: Description
		TableViewerColumn descColumn = new TableViewerColumn(viewer, SWT.NONE);
		descColumn.getColumn().setWidth(275);
		descColumn.getColumn().setText("Parameter Comment");
		descColumn.getColumn().setMoveable(true);
		descColumn.setLabelProvider(new ColumnLabelProvider() {

			@Override
			@SuppressWarnings("unchecked")
			public String getText(Object element) {
				return ((Hashtable<String, String>) element)
						.get(SilverNameEnums.COMMENT.name());
				// return
				// ProjectsViewer.adapterFactory.getParameterComment(scenarioId,
				// (ParameterID) element);

			}

			@Override
			public Color getForeground(Object element) {
				return new Color(PlatformUI.createDisplay(), 155, 155, 155);
			}

		});
		/*
		 * call to editing support to update the array of hashtable to represent
		 * the user desired changes
		 */
		descColumn.setEditingSupport(new CreateScenarioEditingSupport(viewer,
				SilverNameEnums.COMMENT.name(), newScenarioDialog));

	} /* end of createColumns */

}
